const vueCompiler = require("@vue/compiler-dom")

const readVueScript = (file) => {
  const res = vueCompiler.parse(file)
  let template = res.children.find((item) => item.tag === "template") || {}
  template = template ? template.loc.source : ""
  let script = res.children.find((item) => item.tag === "script")
  script = script ? script.children[0].content : ""
  let styleList = res.children.filter((item) => item.tag === "style")
  styleList = styleList.length
    ? styleList.map((item) => item.children.map(({ content }) => content))
    : []
  const [styleListCode] = styleList
  return [template, script, styleListCode]
}
module.exports = readVueScript
